package DataStorageClasses;

import java.sql.Date;

import org.json.JSONException;
import org.json.JSONObject;

public class PayrollSheet 
{
	private static final double otRatio = 1.5;
	
	private long employeeid;
	private String firstName;
	private String lastName;
	private double wage;
	private double totalHours;
	private double overTimeHours;
	private Date start;
	private Date end;
	private double tax;
	
	public PayrollSheet(long empID, String first, String last, double wage, double totalHours, double overHours, Date start,
							Date end, double tax)
	{
		this.employeeid = empID;
		this.firstName = first;
		this.lastName = last;
		this.wage = wage;
		this.totalHours = totalHours;
		this.overTimeHours = overHours;
		this.start = start;
		this.end = end;
		this.tax = tax;
	}
	
	public long getID()
	{
		return employeeid;
	}
	
	public String getFirstName()
	{
		return firstName;
	}
	
	public String getLastName()
	{
		return lastName;
	}
	
	public double getWage()
	{
		return wage;
	}
	
	public double getTotalHours()
	{
		return totalHours;
	}
	
	public double getRegularHours()
	{
		return totalHours - overTimeHours;
	}
	
	public double getOverTimeHours()
	{
		return overTimeHours;
	}
	
	public Date getStartDate()
	{
		return start;
	}
	
	public Date getEnd()
	{
		return end;
	}
	
	public double getTax()
	{
		return tax;
	}
	
	public double getTotalBeforeTax()
	{
		return wage*(getRegularHours() + otRatio*overTimeHours);
	}
	
	public double getTaxDeduction()
	{
		return getTotalBeforeTax()*tax;
	}
	
	public double getTotalAfterTax()
	{
		return getTotalBeforeTax() - getTaxDeduction();
	}
	
	public JSONObject getJSON() throws JSONException
	{
		JSONObject json = new JSONObject();
		
		json.put("employeeid", employeeid);
		json.put("firstName", firstName);
		json.put("lastName", lastName);
		json.put("wage", wage);
		json.put("totalHours", totalHours);
		json.put("overTimeHours", overTimeHours);
		json.put("start", start.toString());
		json.put("end", end.toString());
		json.put("tax", tax);
		json.put("totalBeforeTax", getTotalBeforeTax());
		json.put("totalAfterTax", getTotalAfterTax());
		json.put("taxDeduction", getTaxDeduction());
		
		return json;
	}
}
